home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_1 / rn < prev    next >
Text File  |  1995-03-31  |  8KB  |  188 lines

  1. Article 1938 of comp.sys.handhelds:
  2. >From: AHDINW01@ulkyvx.BITNET
  3. Newsgroups: comp.sys.handhelds
  4. Subject: RN (v3.0) Smaller, faster, leaps small buildings...
  5. Message-ID: <7A2C92B973FFE00F18@ulkyvx.bitnet>
  6. Date: 18 Jun 90 07:27:00 GMT
  7. Lines: 180
  8.  
  9. Hello Again,
  10.  
  11. I got some inspiration and time so here is RN (v3.0):
  12.  
  13. Quick Rerun:
  14.  
  15. RN (v1.0) - My version of RN not yet faster than Yoder's so Yoder's original
  16.             ROUN posted with some slight improvements.
  17. RN (v2.0) - RN optimized little more, bug fixed and support of exponentials
  18.             added.
  19. RN (v3.0) - My original RN version optimized and now faster than Yoder's in
  20.             addition to support of algebraics, tagged, and unit objects!
  21.  
  22.      I have reverted back to my original method of rounding and optimized a
  23. little bit.  As a result, RN is now about 50 bytes smaller and much faster.
  24. This version rounds 50 numbers(integers or floating points) in 8 to 9.3
  25. seconds.  The older version rounded 50 single digit integers fast (about 6
  26. seconds), but the time increased with additional digits, taking up to 40 seconds
  27. to round 50 floating point numbers!
  28.  
  29.      RN is a program which given an object or composite structure will attempt
  30. to correct all numbers appearing anywhere in the object that appear to be
  31. perturbed due to calculator roundoff etc.  RN round's up whenever 4 9's occur
  32. a row in the mantissa of a number and round down when 4 0's occur.  This can
  33. easily be modified for more stricter or relaxed rounding by increasing or
  34. decreasing the number of 0's or 9's.
  35.  
  36. * Note that my definition of what RN does is slightly different than that of
  37. Yoder's original rounder.  ie, I want to round ONLY numbers perturbed by the
  38. calculator, therefore 5.39999999E-57 and 5.38953201E-57 will round to 5.4E-57
  39. and 5.38953201E-57 respectively whereas Yoder's would return zero for both.
  40.  
  41. RN uses:
  42.  
  43. Given:  2.99999501  or (200.00053,-5.34999943E-34) or { 5 "Hi" 4.100002E50 }
  44. Yields: 3          and (200 -5.3E-34)             and { 5 "Hi" 4.1E50 }
  45.  
  46. Given :  '2.0000001*X^2.23599999 + 7.3100000432'
  47. Yields:  '2*X^2.236 + 7.31'
  48.  
  49. Given :  ANS: { 49.9992_ft '2-6.50400003E35*X' [ [ (1.00001,5) ] [ (2,3) ] ] }
  50. Yields:  ANS: { 50_ft '2-6.504E35*X' [ [ (1,5) ] [ (2,3) ] ] }
  51.  
  52. And so on...
  53.  
  54. As a side note:
  55.      This program does make use of the ^MATCH command, and I believe I am the
  56. first to use it in a posted program (or at least in a non-table lookup
  57. setting).  Does anyone else have any clever uses for ^/vMATCH.  I would be
  58. interested in seeing them even if not their not incorporated in a program.
  59. This command appears to have lots of hidden potential.  For example, programs
  60. using ^/vMATCH can be recursively called yielding obscure but interesting
  61. results.  People should be looking hard at this command.
  62.  
  63. Here's some food for thought:
  64.  
  65. If a binary tree is defined in the form, '((A+B)+C)+((D+E)+(F+(G+H))'  where
  66. '+' represents a node of the tree such as:
  67.  
  68.                                 +
  69.                                / \
  70.                               /   \
  71.                              /     \
  72.                             /       \
  73.                            +         +
  74.                          / \        / \
  75.                         /   \      /   \
  76.                        /     \    /     \
  77.                       +       C  +       +
  78.                      / \        / \     / \
  79.                     A   B      D   E   F   \
  80.                                             +
  81.                                            / \
  82.                                           G   H
  83.  
  84. then shouldn't it be possible to write routines to manipulate the tree using
  85. ^/vMATCH?  Anybody want to comment?
  86.  
  87.  
  88. BTW, if you do play around with ^/vMATCH, I suggest setting flag -53
  89. (precedence flag) to display all parenthesis.
  90.  
  91. ============================================================================
  92. HP (if your listening), how about this for ^/vMATCH:
  93.  
  94.    { 'pattern' 'true replacement' ['false replacement'] ['conditional'] }
  95.  
  96. where 'pattern' is the subexpression for which to search, 'true/false
  97. replacement' is the new subexpression, and 'conditional' specifies which
  98. replacement is performed.
  99.  
  100. To facilitate the specification of the pattern, the 'pattern' and
  101. 'replacements' AND 'conditional' can contain "wildcard" names that will match
  102. any subexpression.  A wildcard variable is specified by prefixing any variable
  103. name with the & character.  I also want a wildcard operator variable (such
  104. as % character) which will match any operator.  Typical uses could be:
  105.  
  106. { '&x %o &y' '&x %o &y' '&y - &x' 'condition' } or
  107.  
  108. { '%o( &x )' 'SIN(&x)'  'COS(&x)' 'condition' }
  109.  
  110. and lastly, I want new functions (and old ones back):
  111.  
  112. EXGET, EXSUB, OBGET, OBSUB, etc...
  113.  
  114. LEVEL - given an algebraic, it returns the number of levels present, when used
  115.         in the 'condition' portion of the ^/vMATCH list it returns the current
  116.         level of its wildcard variable in the expression or a boolean value 1
  117.         if the current level matches the argument.  Therefore:
  118.  
  119. Given : '((X+2)+Y)'  LEVEL
  120. Yields: 2
  121.  
  122. Given : { &x  'RN(&x)' '&x' 'LEVEL(&x) == LEVEL(3)' } ^/vMATCH
  123. Yields: Replace &x with RN(&x) only for level 3 subexpressions.
  124.  
  125. Could this be implemented easily, doesn't look too tough too me (what do I
  126. know) and would greatly enhance the calculator's usefulness!  With not much
  127. more effort this thing could be doing forward searches, back-tracking,
  128. etc...(eeiioohh, I'm getting cold chills).
  129.  
  130. ============================================================================
  131. RN:  Bytes #55BAh, 667                   ; version 3.0
  132.  
  133. << -> eq                                 ; -> eq added so RN could be called
  134.   << eq DUP -> TYPE t                    ; as a function.  Now necessary!
  135.      << CASE t NOT THEN
  136.            DUP SIGN SWAP DUP DUP
  137.            IF THEN XPON SWAP MANT END    ; MANT doesn't like 0
  138.            ->STR DUP "0000" POS          ; Change "0000" as desired
  139.            IF DUP NOT
  140.              THEN DROP
  141.              ELSE 1 SWAP 1 - SUB
  142.            END
  143.            DUP "9999" POS                ; Change "9999" as desired
  144.            IF DUP NOT
  145.              THEN DROP OBJ->
  146.              ELSE SWAP OBJ-> SWAP NEG RND
  147.            END
  148.            10 ROT ^ * *
  149.         END IF t 1 ==                    ; Complex Number ?
  150.         THEN
  151.            C->R SWAP RN SWAP RN
  152.            IF DUP THEN R->C ELSE DROP END
  153.         END IF t 3 == t 4 == OR
  154.         THEN                             ; Real or Complex Array ?
  155.            OBJ-> DUP OBJ->
  156.            IF 2 == THEN * END
  157.            -> d s << 1 s START RN s ROLL NEXT d ->ARRY >>
  158.         END IF t 5 ==                    ; List ?
  159.         THEN
  160.            OBJ-> -> s << 1 s START RN s ROLL NEXT s ->LIST >>
  161.         END IF t 9 == 1                  ; Algebraic ?
  162.                tmp SAME NOT AND          ; No points for beauty here!
  163.         THEN
  164.            1 'tmp' STO
  165.            { &x 'RN(&x)' } ^MATCH        ; Must use (UP)MATCH!
  166.            DROP EVAL
  167.            'tmp' PURGE
  168.         END IF t 12 ==                   ; Tagged Object ?
  169.         THEN
  170.            OBJ-> SWAP RN SWAP ->TAG
  171.         END IF t 13 ==                   ; Unit Object ?
  172.         THEN
  173.            OBJ-> SWAP RN SWAP _          ; _ is the underscore
  174.         END
  175.      END
  176.     >>
  177.   >>
  178. >>
  179. ============================================================================
  180.  
  181.                           Aaron Dinwiddie
  182.                            ==> Agima <==                    ahdinw01@ulkyvx
  183.  
  184. How much is an out of warranty dead HP28S worth?
  185. ============================================================================
  186.  
  187.  
  188.